package com.example.controller;


import com.example.common.Result;
import com.example.entity.Admin;
import com.example.entity.Helper;
import com.example.entity.User;
import com.example.service.AdminService;
import com.example.service.HelperService;
import com.example.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/helper")
public class HelperController {
    @Autowired
    private HelperService helperService;
    @Autowired
    private UserService userService;




    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(User user,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<User> page = helperService.selectPage(user, pageNum, pageSize);
        System.out.println("------");
        return Result.success(page);
    }

        /**
         * 新增
         */
        @PostMapping("/add")
        public Result add(@RequestBody Admin admin) {
            helperService.add(admin);
            return Result.success();
        }

        /**
         * 删除
         */
        @DeleteMapping("/delete/{id}")
        public Result deleteById(@PathVariable Integer id) {
            helperService.deleteById(id);
            return Result.success();
        }

        /**
         * 批量删除
         */
        @DeleteMapping("/delete/batch")
        public Result deleteBatch(@RequestBody List<Integer> ids) {
            helperService.deleteBatch(ids);
            return Result.success();
        }

        /**
         * 修改
         */
        @PutMapping("/update")
        public Result updateById(@RequestBody Admin admin) {
            helperService.updateById(admin);
            return Result.success();
        }

        /**
         * 根据ID查询
         */
        @GetMapping("/selectById/{id}")
        public Result selectById(@PathVariable Integer id) {
            Helper admin = helperService.selectById1(id);
            return Result.success(admin);
        }

        /**
         * 查询所有
         */
        @GetMapping("/selectAll")
        public Result selectAll(Admin admin ) {
            List<Helper> list = helperService.selectAll(admin);
            return Result.success(list);
        }

        /**
         * 分页查询
         */
        @GetMapping("/selectPage1")
        public Result selectPage1(Admin admin,
                                 @RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize) {
            PageInfo<Helper> page = helperService.selectPage1(admin, pageNum, pageSize);
            return Result.success(page);
        }

    }


